package com.yunshan.mp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yunshan.common.utils.StringUtils;
import com.yunshan.mp.domain.ResultServe;
import com.yunshan.mp.service.impl.MpServeInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunshan.common.annotation.Log;
import com.yunshan.common.core.controller.BaseController;
import com.yunshan.common.core.domain.AjaxResult;
import com.yunshan.common.enums.BusinessType;
import com.yunshan.mp.domain.MpServeInfo;
import com.yunshan.mp.service.IMpServeInfoService;
import com.yunshan.common.utils.poi.ExcelUtil;
import com.yunshan.common.core.page.TableDataInfo;

/**
 * 服务设置Controller
 * 
 * @author yunshan
 * @date 2025-01-20
 */
@Api(tags = "服务设置")
@RestController
@RequestMapping("/mp/serve")
public class MpServeInfoController extends BaseController
{
    @Autowired
    private IMpServeInfoService mpServeInfoService;

    /**
     * 查询服务设置列表
     */
    @ApiOperation(value = "查询服务设置列表")
    @PreAuthorize("@ss.hasPermi('mp:serve:list')")
    @GetMapping("/list")
    public TableDataInfo list(MpServeInfo mpServeInfo)
    {
        if ("0".equals(mpServeInfo.getServeType())){
            mpServeInfo.setServeType(null);
        }
        startPage();
        List<MpServeInfo> list = mpServeInfoService.selectMpServeInfoList(mpServeInfo);
        return getDataTable(list);
    }

    /**
     * 导出服务设置列表
     */
    @ApiOperation(value = "导出服务设置列表")
    @PreAuthorize("@ss.hasPermi('mp:serve:export')")
    @Log(title = "服务设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MpServeInfo mpServeInfo)
    {
        List<MpServeInfo> list = mpServeInfoService.selectMpServeInfoList(mpServeInfo);
        ExcelUtil<MpServeInfo> util = new ExcelUtil<MpServeInfo>(MpServeInfo.class);
        util.exportExcel(response, list, "服务设置数据");
    }

    /**
     * 获取服务设置详细信息
     */
    @ApiOperation(value = "获取服务设置详细信息")
    @PreAuthorize("@ss.hasPermi('mp:serve:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mpServeInfoService.selectMpServeInfoById(id));
    }

    /**
     * 新增服务设置
     */
    @ApiOperation(value = "新增服务设置")
    @PreAuthorize("@ss.hasPermi('mp:serve:add')")
    @Log(title = "服务设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpServeInfo mpServeInfo)
    {
        if (mpServeInfo.getServeType() == null || StringUtils.isEmpty(mpServeInfo.getName())){
            return AjaxResult.error("请先将内容填写完整~");
        }
        return toAjax(mpServeInfoService.insertMpServeInfo(mpServeInfo));
    }

    /**
     * 修改服务设置
     */
    @ApiOperation(value = "修改服务设置")
    @PreAuthorize("@ss.hasPermi('mp:serve:edit')")
    @Log(title = "服务设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpServeInfo mpServeInfo)
    {
        return toAjax(mpServeInfoService.updateMpServeInfo(mpServeInfo));
    }

    /**
     * 删除服务设置
     */
    @ApiOperation(value = "删除服务设置")
    @PreAuthorize("@ss.hasPermi('mp:serve:remove')")
    @Log(title = "服务设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpServeInfoService.deleteMpServeInfoByIds(ids));
    }

    /**
     * 查询服务设置树状结构
     */
    @ApiOperation(value = "查询服务设置树状结构")
    @PreAuthorize("@ss.hasPermi('mp:serve:list')")
    @GetMapping("/queryServe")
    public TableDataInfo queryServe(MpServeInfo mpServeInfo)
    {
        return getDataTable(mpServeInfoService.selectResultServeList(mpServeInfo));
    }

}
